package question.T0302_1_News;

import java.util.ArrayList;
import java.util.List;

class NewsChannelImpl implements NewsChannel {
    private String name;
    private List<Subscriber> subscribers = new ArrayList<>();
    private NewsPlatform platform;

    public NewsChannelImpl(String name, NewsPlatform platform) {
        this.name = name;
        this.platform = platform;
    }

    @Override
    public void subscribe(Subscriber subscriber) {
        subscribers.add(subscriber);
        System.out.println(subscriber + " 订阅了 " + name);
    }

    @Override
    public void unsubscribe(Subscriber subscriber) {
        subscribers.remove(subscriber);
        System.out.println(subscriber + " 取消订阅 " + name);
    }

    @Override
    public void publishArticle(Article article) {
        platform.storeArticle(article);
        notifySubscribers(article.getTitle());
    }

    private void notifySubscribers(String articleTitle) {
        // 在这里添加或者修改代码

        // 可修改部分结束
    }

    @Override
    public String getName() {
        return name;
    }
}
